package com.xishu.dao.jpa;

import com.xishu.entity.feedback.Feedback;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import javax.persistence.Tuple;
import java.util.List;

public interface FeedbackDao extends JpaRepository<Feedback, Long>, JpaSpecificationExecutor<Feedback> {
    /**
     * 顾客反馈，带反馈理由参数查
     * @param shopIdList
     * @param startTime
     * @param endTime
     * @param timeUnit
     * @return
     */
    @Query(value = "select  FROM_UNIXTIME(create_time / 1000, :timeUnit) as x, avg(star) as value " +
            "from feed_back m " +
            "where m.shop_id in (:shopIdList) and m.create_time >= :startTime and m.create_time <= :endTime and m.type = 2 " +
            "group by FROM_UNIXTIME(create_time / 1000, :timeUnit)", nativeQuery = true)
    public List<Tuple> report(List<Long> shopIdList, Long startTime, Long endTime, String timeUnit);
}
